<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Spring 异步处理机制深度解析 | 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        :root {
            --primary: #2563eb;
            --primary-light: #3b82f6;
            --secondary: #7c3aed;
            --dark: #1e293b;
            --light: #f8fafc;
            --gray: #64748b;
            --accent: #10b981;
        }
        
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: var(--dark);
            line-height: 1.6;
            background-color: #f5f7fa;
        }
        
        h1, h2, h3, h4, h5, h6 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
            color: var(--dark);
        }
        
        .hero {
            background: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
        }
        
        .code-block {
            background-color: #1e293b;
            border-radius: 0.5rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
        
        .card {
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
        
        .card:hover {
            transform: translateY(-4px);
            box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
        }
        
        .highlight {
            position: relative;
        }
        
        .highlight::before {
            content: "";
            position: absolute;
            left: -4px;
            top: 0;
            bottom: 0;
            width: 4px;
            background-color: var(--primary);
            border-radius: 4px 0 0 4px;
        }
        
        .drop-cap::first-letter {
            float: left;
            font-size: 3.5rem;
            line-height: 1;
            margin-right: 0.5rem;
            color: var(--primary);
            font-weight: bold;
        }
        
        .footer {
            background-color: #0f172a;
        }
        
        .footer a:hover {
            color: var(--primary-light);
        }
        
        .scroll-indicator {
            animation: bounce 2s infinite;
        }
        
        @keyframes bounce {
            0%, 20%, 50%, 80%, 100% {
                transform: translateY(0);
            }
            40% {
                transform: translateY(-10px);
            }
            60% {
                transform: translateY(-5px);
            }
        }
        
        .tooltip:hover .tooltip-text {
            visibility: visible;
            opacity: 1;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero text-white py-20 md:py-32 relative overflow-hidden">
        <div class="absolute inset-0 bg-black opacity-30"></div>
        <div class="container mx-auto px-6 relative z-10">
            <div class="max-w-3xl mx-auto text-center">
                <span class="inline-block bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm font-medium mb-4">Spring 高级特性</span>
                <h1 class="text-4xl md:text-5xl lg:text-6xl font-bold mb-6 leading-tight">Spring 异步处理机制深度解析</h1>
                <p class="text-xl md:text-2xl opacity-90 mb-10 max-w-2xl mx-auto">
                    探索 @Async 注解背后的实现原理，掌握高性能异步任务处理的最佳实践
                </p>
                <div class="flex justify-center space-x-4">
                    <a href="#overview" class="bg-white text-blue-600 px-6 py-3 rounded-lg font-medium hover:bg-opacity-90 transition duration-300 inline-flex items-center">
                        <i class="fas fa-book-open mr-2"></i> 开始阅读
                    </a>
                    <a href="#mermaid" class="bg-transparent border-2 border-white text-white px-6 py-3 rounded-lg font-medium hover:bg-white hover:text-blue-600 transition duration-300 inline-flex items-center">
                        <i class="fas fa-project-diagram mr-2"></i> 架构图解
                    </a>
                </div>
            </div>
        </div>
        <div class="absolute bottom-6 left-1/2 transform -translate-x-1/2 scroll-indicator">
            <i class="fas fa-chevron-down text-2xl text-white opacity-70"></i>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-16 max-w-5xl">
        <!-- Overview Section -->
        <section id="overview" class="mb-20">
            <div class="flex items-center mb-10">
                <div class="flex-shrink-0 mr-4">
                    <div class="w-12 h-12 rounded-full bg-blue-100 flex items-center justify-center">
                        <i class="fas fa-info-circle text-blue-600 text-xl"></i>
                    </div>
                </div>
                <h2 class="text-3xl font-bold">Spring 异步处理的概述</h2>
            </div>
            
            <div class="bg-white rounded-xl p-6 md:p-8 card mb-8">
                <p class="text-lg text-gray-700 drop-cap">
                    Spring 异步处理机制通过 <code class="bg-blue-50 text-blue-600 px-2 py-1 rounded">@Async</code> 注解提供了简便的异步任务执行方式。通过在方法上加上 <code class="bg-blue-50 text-blue-600 px-2 py-1 rounded">@Async</code> 注解，Spring 会自动将该方法的执行异步化，通常是将方法的执行交给一个配置好的线程池来处理，而不会阻塞调用线程。
                </p>
            </div>
            
            <h3 class="text-2xl font-semibold mb-4 text-gray-800 flex items-center">
                <i class="fas fa-code mr-3 text-blue-500"></i> 关键源码
            </h3>
            
            <div class="code-block mb-8">
                <pre class="text-gray-300 p-6 overflow-x-auto"><code>@Target(value=TYPE)
@Retention(value=RUNTIME)
@EnableAspectJAutoProxy(proxyTargetClass=false)
@Import(value=AsyncConfiguration.class)
@ComponentScan(value="org.springframework.scheduling.annotation")
public @interface EnableAsync {
}</code></pre>
            </div>
            
            <div class="bg-blue-50 border-l-4 border-blue-500 p-4 mb-8 rounded-r">
                <div class="flex">
                    <div class="flex-shrink-0">
                        <i class="fas fa-lightbulb text-blue-500"></i>
                    </div>
                    <div class="ml-3">
                        <p class="text-blue-800">
                            <span class="font-semibold">核心理解:</span> <code class="bg-white text-blue-600 px-1 py-0.5 rounded">@EnableAsync</code> 注解开启异步功能，通常在配置类中使用。这个注解的作用是启动 Spring 的异步功能，启用基于代理的异步执行。
                        </p>
                    </div>
                </div>
            </div>
        </section>
        
        <!-- Async Annotation Section -->
        <section id="async-annotation" class="mb-20">
            <div class="flex items-center mb-10">
                <div class="flex-shrink-0 mr-4">
                    <div class="w-12 h-12 rounded-full bg-purple-100 flex items-center justify-center">
                        <i class="fas fa-tag text-purple-600 text-xl"></i>
                    </div>
                </div>
                <h2 class="text-3xl font-bold">@Async 注解的使用</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-10">
                <div class="bg-white rounded-xl p-6 card highlight">
                    <h3 class="text-xl font-semibold mb-3 text-gray-800 flex items-center">
                        <i class="fas fa-info-circle text-purple-500 mr-2"></i> 注解说明
                    </h3>
                    <p class="text-gray-700">
                        <code class="bg-purple-50 text-purple-600 px-2 py-1 rounded">@Async</code> 是 Spring 异步机制的核心注解，标记一个方法为异步方法。使用 <code class="bg-purple-50 text-purple-600 px-2 py-1 rounded">@Async</code> 注解的方法将会在后台线程池中执行，而不影响主线程的执行。
                    </p>
                </div>
                
                <div class="bg-white rounded-xl p-6 card highlight">
                    <h3 class="text-xl font-semibold mb-3 text-gray-800 flex items-center">
                        <i class="fas fa-key text-purple-500 mr-2"></i> 关键源码
                    </h3>
                    <div class="code-block">
                        <pre class="text-gray-300 p-4 overflow-x-auto text-sm"><code>@Target(value=METHOD)
@Retention(value=RUNTIME)
@Async
public @interface Async {
}</code></pre>
                    </div>
                </div>
            </div>
            
            <h3 class="text-2xl font-semibold mb-4 text-gray-800 flex items-center">
                <i class="fas fa-code mr-3 text-purple-500"></i> 示例代码
            </h3>
            
            <div class="code-block mb-8">
                <pre class="text-gray-300 p-6 overflow-x-auto"><code>@Service
public class MyService {

    @Async
    public void asyncMethod() {
        // 模拟耗时操作
        System.out.println("Start Async Task: " + Thread.currentThread().getName());
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("End Async Task: " + Thread.currentThread().getName());
    }
}</code></pre>
            </div>
            
            <div class="bg-purple-50 border-l-4 border-purple-500 p-4 rounded-r">
                <div class="flex">
                    <div class="flex-shrink-0">
                        <i class="fas fa-lightbulb text-purple-500"></i>
                    </div>
                    <div class="ml-3">
                        <p class="text-purple-800">
                            <span class="font-semibold">代码解析:</span> 在上面的例子中，<code class="bg-white text-purple-600 px-1 py-0.5 rounded">asyncMethod()</code> 方法被 <code class="bg-white text-purple-600 px-1 py-0.5 rounded">@Async</code> 注解标记，意味着这个方法的执行会在独立的线程中进行，不会阻塞主线程。
                        </p>
                    </div>
                </div>
            </div>
        </section>
        
        <!-- Proxy Mechanism Section -->
        <section id="proxy-mechanism" class="mb-20">
            <div class="flex items-center mb-10">
                <div class="flex-shrink-0 mr-4">
                    <div class="w-12 h-12 rounded-full bg-green-100 flex items-center justify-center">
                        <i class="fas fa-project-diagram text-green-600 text-xl"></i>
                    </div>
                </div>
                <h2 class="text-3xl font-bold">异步任务执行的代理机制</h2>
            </div>
            
            <div class="bg-white rounded-xl p-6 md:p-8 card mb-8">
                <p class="text-lg text-gray-700">
                    Spring 的异步处理是基于代理模式实现的。Spring 会为带有 <code class="bg-green-50 text-green-600 px-2 py-1 rounded">@Async</code> 注解的方法创建一个代理对象，所有对该方法的调用都会通过代理来转发，代理会将方法的执行交给线程池来执行。
                </p>
            </div>
            
            <h3 class="text-2xl font-semibold mb-4 text-gray-800 flex items-center">
                <i class="fas fa-code mr-3 text-green-500"></i> 关键源码
            </h3>
            
            <div class="code-block mb-8">
                <pre class="text-gray-300 p-6 overflow-x-auto"><code>public class AsyncAnnotationBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof AsyncConfigurer) {
            // 获取线程池配置
            Executor executor = ((AsyncConfigurer) bean).getAsyncExecutor();
            return new AsyncAnnotationBeanPostProcessor(executor);
        }
        return bean;
    }
}</code></pre>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-green-50 border-l-4 border-green-500 p-4 rounded-r">
                    <div class="flex">
                        <div class="flex-shrink-0">
                            <i class="fas fa-lightbulb text-green-500"></i>
                        </div>
                        <div class="ml-3">
                            <p class="text-green-800">
                                <span class="font-semibold">核心组件:</span> <code class="bg-white text-green-600 px-1 py-0.5 rounded">AsyncAnnotationBeanPostProcessor</code> 会扫描所有被 <code class="bg-white text-green-600 px-1 py-0.5 rounded">@Async</code> 注解标记的方法，创建代理对象来异步执行这些方法。
                            </p>
                        </div>
                    </div>
                </div>
                
                <div class="bg-green-50 border-l-4 border-green-500 p-4 rounded-r">
                    <div class="flex">
                        <div class="flex-shrink-0">
                            <i class="fas fa-lightbulb text-green-500"></i>
                        </div>
                        <div class="ml-3">
                            <p class="text-green-800">
                                <span class="font-semibold">代理实现:</span> Spring 默认使用 JDK 动态代理和 CGLIB 代理来实现方法的异步执行，具体取决于是否需要代理目标类的方法。
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </section>
        
        <!-- TaskExecutor Section -->
        <section id="task-executor" class="mb-20">
            <div class="flex items-center mb-10">
                <div class="flex-shrink-0 mr-4">
                    <div class="w-12 h-12 rounded-full bg-yellow-100 flex items-center justify-center">
                        <i class="fas fa-tasks text-yellow-600 text-xl"></i>
                    </div>
                </div>
                <h2 class="text-3xl font-bold">TaskExecutor 的配置和执行</h2>
            </div>
            
            <div class="bg-white rounded-xl p-6 md:p-8 card mb-8">
                <p class="text-lg text-gray-700">
                    Spring 异步执行的任务是通过 <code class="bg-yellow-50 text-yellow-600 px-2 py-1 rounded">TaskExecutor</code> 接口实现的。<code class="bg-yellow-50 text-yellow-600 px-2 py-1 rounded">TaskExecutor</code> 是 Spring 用来提交异步任务的主要接口，它提供了一个简单的执行方法。
                </p>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div class="code-block">
                    <pre class="text-gray-300 p-6 overflow-x-auto"><code>public interface TaskExecutor {
    void execute(Runnable task);
}</code></pre>
                </div>
                
                <div class="bg-yellow-50 border-l-4 border-yellow-500 p-4 rounded-r self-center">
                    <div class="flex">
                        <div class="flex-shrink-0">
                            <i class="fas fa-info-circle text-yellow-500"></i>
                        </div>
                        <div class="ml-3">
                            <p class="text-yellow-800">
                                <span class="font-semibold">接口说明:</span> <code class="bg-white text-yellow-600 px-1 py-0.5 rounded">execute()</code> 方法接收一个 <code class="bg-white text-yellow-600 px-1 py-0.5 rounded">Runnable</code> 任务并将其提交给线程池执行。
                            </p>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="mb-8">
                <h3 class="text-2xl font-semibold mb-4 text-gray-800 flex items-center">
                    <i class="fas fa-cog mr-3 text-yellow-500"></i> 线程池配置示例
                </h3>
                
                <div class="code-block">
                    <pre class="text-gray-300 p-6 overflow-x-auto"><code>@Configuration
@EnableAsync
public class AsyncConfig implements AsyncConfigurer {

    @Override
    public Executor getAsyncExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(5);
        executor.setMaxPoolSize(10);
        executor.setQueueCapacity(25);
        executor.setThreadNamePrefix("async-");
        executor.initialize();
        return executor;
    }
}</code></pre>
                </div>
                
                <div class="bg-yellow-50 border-l-4 border-yellow-500 p-4 rounded-r mt-4">
                    <div class="flex">
                        <div class="flex-shrink-0">
                            <i class="fas fa-lightbulb text-yellow-500"></i>
                        </div>
                        <div class="ml-3">
                            <p class="text-yellow-800">
                                在 <code class="bg-white text-yellow-600 px-1 py-0.5 rounded">AsyncConfig</code> 中，我们配置了 <code class="bg-white text-yellow-600 px-1 py-0.5 rounded">ThreadPoolTaskExecutor</code> 作为异步执行的线程池，它支持灵活的线程池配置。
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </section>
        
        <!-- Result Handling Section -->
        <section id="result-handling" class="mb-20">
            <div class="flex items-center mb-10">
                <div class="flex-shrink-0 mr-4">
                    <div class="w-12 h-12 rounded-full bg-indigo-100 flex items-center justify-center">
                        <i class="fas fa-exchange-alt text-indigo-600 text-xl"></i>
                    </div>
                </div>
                <h2 class="text-3xl font-bold">异步执行的返回结果处理</h2>
            </div>
            
            <div class="bg-white rounded-xl p-6 md:p-8 card mb-8">
                <p class="text-lg text-gray-700">
                    异步方法可以返回 <code class="bg-indigo-50 text-indigo-600 px-2 py-1 rounded">Future</code> 或者 <code class="bg-indigo-50 text-indigo-600 px-2 py-1 rounded">CompletableFuture</code> 对象，用于表示异步执行的结果。通过 <code class="bg-indigo-50 text-indigo-600 px-2 py-1 rounded">Future</code> 或 <code class="bg-indigo-50 text-indigo-600 px-2 py-1 rounded">CompletableFuture</code>，调用者可以获取异步执行的结果或处理异常。
                </p>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div class="code-block">
                    <pre class="text-gray-300 p-6 overflow-x-auto"><code>@Async
public CompletableFuture&lt;String&gt; asyncMethod() {
    // 异步方法返回 CompletableFuture
    return CompletableFuture.completedFuture("Result");
}</code></pre>
                </div>
                
                <div class="bg-indigo-50 border-l-4 border-indigo-500 p-4 rounded-r self-center">
                    <div class="flex">
                        <div class="flex-shrink-0">
                            <i class="fas fa-info-circle text-indigo-500"></i>
                        </div>
                        <div class="ml-3">
                            <p class="text-indigo-800">
                                <span class="font-semibold">特性说明:</span> <code class="bg-white text-indigo-600 px-1 py-0.5 rounded">CompletableFuture</code> 是 Java 8 引入的，可以提供更强大的异步编程能力，允许开发者通过链式调用来处理异步操作。
                            </p>
                        </div>
                    </div>
                </div>
            </div>
            
            <h3 class="text-2xl font-semibold mb-4 text-gray-800 flex items-center">
                <i class="fas fa-code mr-3 text-indigo-500"></i> 调用示例
            </h3>
            
            <div class="code-block mb-8">
                <pre class="text-gray-300 p-6 overflow-x-auto"><code>@Autowired
private MyService myService;

public void startAsyncTask() {
    CompletableFuture&lt;String&gt; result = myService.asyncMethod();
    result.thenAccept(r -> System.out.println("Async Result: " + r));
}</code></pre>
            </div>
            
            <div class="bg-indigo-50 border-l-4 border-indigo-500 p-4 rounded-r">
                <div class="flex">
                    <div class="flex-shrink-0">
                        <i class="fas fa-lightbulb text-indigo-500"></i>
                    </div>
                    <div class="ml-3">
                        <p class="text-indigo-800">
                            在调用异步方法时，我们可以通过 <code class="bg-white text-indigo-600 px-1 py-0.5 rounded">thenAccept</code> 等方法来处理异步操作完成后的结果。
                        </p>
                    </div>
                </div>
            </div>
        </section>
        
        <!-- Exception Handling Section -->
        <section id="exception-handling" class="mb-20">
            <div class="flex items-center mb-10">
                <div class="flex-shrink-0 mr-4">
                    <div class="w-12 h-12 rounded-full bg-red-100 flex items-center justify-center">
                        <i class="fas fa-exclamation-triangle text-red-600 text-xl"></i>
                    </div>
                </div>
                <h2 class="text-3xl font-bold">异步方法的异常处理</h2>
            </div>
            
            <div class="bg-white rounded-xl p-6 md:p-8 card mb-8">
                <p class="text-lg text-gray-700">
                    在异步方法执行时，如果出现异常，Spring 会将异常包装成 <code class="bg-red-50 text-red-600 px-2 py-1 rounded">AsyncExecutionException</code>。开发者可以通过在 <code class="bg-red-50 text-red-600 px-2 py-1 rounded">@Async</code> 方法上使用 <code class="bg-red-50 text-red-600 px-2 py-1 rounded">@ExceptionHandler</code> 注解来处理异常。
                </p>
            </div>
            
            <div class="code-block mb-8">
                <pre class="text-gray-300 p-6 overflow-x-auto"><code>@Async
public void asyncMethod() {
    try {
        // 可能抛出异常的代码
        throw new RuntimeException("Test Exception");
    } catch (Exception e) {
        // 异常处理
        System.out.println("Async Task Error: " + e.getMessage());
    }
}</code></pre>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-red-50 border-l-4 border-red-500 p-4 rounded-r">
                    <div class="flex">
                        <div class="flex-shrink-0">
                            <i class="fas fa-lightbulb text-red-500"></i>
                        </div>
                        <div class="ml-3">
                            <p class="text-red-800">
                                <span class="font-semibold">异常捕获:</span> 在 <code class="bg-white text-red-600 px-1 py-0.5 rounded">@Async</code> 注解的方法内部，出现的异常可以通过 <code class="bg-white text-red-600 px-1 py-0.5 rounded">try-catch</code> 来捕获并处理。
                            </p>
                        </div>
                    </div>
                </div>
                
                <div class="bg-red-50 border-l-4 border-red-500 p-4 rounded-r">
                    <div class="flex">
                        <div class="flex-shrink-0">
                            <i class="fas fa-lightbulb text-red-500"></i>
                        </div>
                        <div class="ml-3">
                            <p class="text-red-800">
                                <span class="font-semibold">全局处理:</span> 也可以通过 Spring 提供的 <code class="bg-white text-red-600 px-1 py-0.5 rounded">@ExceptionHandler</code> 来集中处理异步任务中的异常。
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </section>
        
        <!-- Lifecycle Section -->
        <section id="lifecycle" class="mb-20">
            <div class="flex items-center mb-10">
                <div class="flex-shrink-0 mr-4">
                    <div class="w-12 h-12 rounded-full bg-teal-100 flex items-center justify-center">
                        <i class="fas fa-recycle text-teal-600 text-xl"></i>
                    </div>
                </div>
                <h2 class="text-3xl font-bold">异步执行的生命周期</h2>
            </div>
            
            <div class="bg-white rounded-xl p-6 md:p-8 card mb-8">
                <p class="text-lg text-gray-700">
                    Spring 的异步任务在执行时遵循生命周期管理。我们可以通过配置 <code class="bg-teal-50 text-teal-600 px-2 py-1 rounded">TaskExecutor</code> 和 <code class="bg-teal-50 text-teal-600 px-2 py-1 rounded">AsyncConfigurer</code> 来精确控制线程池的行为，并通过实现 <code class="bg-teal-50 text-teal-600 px-2 py-1 rounded">AsyncListener</code> 来监听异步任务的生命周期。
                </p>
            </div>
            
            <div class="code-block mb-8">
                <pre class="text-gray-300 p-6 overflow-x-auto"><code>public interface AsyncListener {
    void onStart();
    void onComplete();
    void onError(Throwable t);
}</code></pre>
            </div>
            
            <div class="bg-teal-50 border-l-4 border-teal-500 p-4 rounded-r">
                <div class="flex">
                    <div class="flex-shrink-0">
                        <i class="fas fa-lightbulb text-teal-500"></i>
                    </div>
                    <div class="ml-3">
                        <p class="text-teal-800">
                            <span class="font-semibold">生命周期回调:</span> <code class="bg-white text-teal-600 px-1 py-0.5 rounded">AsyncListener</code> 允许开发者在任务开始、完成或出错时执行特定的操作，例如记录日志、通知用户等。
                        </p>
                    </div>
                </div>
            </div>
        </section>
        
        <!-- Mermaid Diagram Section -->
        <section id="mermaid" class="mb-20">
            <div class="flex items-center mb-10">
                <div class="flex-shrink-0 mr-4">
                    <div class="w-12 h-12 rounded-full bg-pink-100 flex items-center justify-center">
                        <i class="fas fa-network-wired text-pink-600 text-xl"></i>
                    </div>
                </div>
                <h2 class="text-3xl font-bold">Spring 异步机制架构图解</h2>
            </div>
            
            <div class="bg-white rounded-xl p-6 md:p-8 card">
                <div class="mermaid">
                    graph TD
                        A[调用者] -->|调用异步方法| B[@Async方法]
                        B --> C[AsyncAnnotationBeanPostProcessor]
                        C --> D[创建代理对象]
                        D --> E[提交任务到线程池]
                        E --> F[TaskExecutor]
                        F --> G[执行任务]
                        G --> H[返回结果或异常]
                        
                        classDef node fill:#f8fafc,stroke:#64748b,stroke-width:2px;
                        classDef async fill:#e0f2fe,stroke:#0ea5e9;
                        classDef executor fill:#dbeafe,stroke:#3b82f6;
                        classDef proxy fill:#ede9fe,stroke:#8b5cf6;
                        
                        class A,B,H node;
                        class C,D proxy;
                        class E,F,G executor;
                        class B async;
                </div>
            </div>
        </section>
        
        <!-- Summary Section -->
        <section class="mb-20">
            <div class="bg-gradient-to-r from-blue-500 to-purple-600 rounded-xl p-8 text-white">
                <h3 class="text-2xl font-bold mb-4">核心要点总结</h3>
                <ul class="space-y-3">
                    <li class="flex items-start">
                        <i class="fas fa-check-circle mt-1 mr-3"></i>
                        <span><code class="bg-white bg-opacity-20 px-2 py-1 rounded">@EnableAsync</code> 注解开启 Spring 的异步处理功能</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle mt-1 mr-3"></i>
                        <span><code class="bg-white bg-opacity-20 px-2 py-1 rounded">@Async</code> 注解标记的方法会被异步执行</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle mt-1 mr-3"></i>
                        <span>异步执行基于代理模式实现，由 <code class="bg-white bg-opacity-20 px-2 py-1 rounded">AsyncAnnotationBeanPostProcessor</code> 处理</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle mt-1 mr-3"></i>
                        <span>通过配置 <code class="bg-white bg-opacity-20 px-2 py-1 rounded">TaskExecutor</code> 可以自定义线程池行为</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle mt-1 mr-3"></i>
                        <span>异步方法可以返回 <code class="bg-white bg-opacity-20 px-2 py-1 rounded">Future</code> 或 <code class="bg-white bg-opacity-20 px-2 py-1 rounded">CompletableFuture</code> 处理结果</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle mt-1 mr-3"></i>
                        <span>通过 <code class="bg-white bg-opacity-20 px-2 py-1 rounded">AsyncListener</code> 可以监听异步任务生命周期</span>
                    </li>
                </ul>
            </div>
        </section>
    </main>
    
    <!-- Footer -->
    <footer class="footer text-white py-12">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto text-center">
                <h3 class="text-xl font-semibold mb-4">技术小馆</h3>
                <p class="text-gray-400 mb-6">探索技术之美，分享编程之乐</p>
                <a href="http://www.yuque.com/jtostring" class="text-blue-400 hover:text-blue-300 transition duration-300 inline-flex items-center">
                    <i class="fas fa-external-link-alt mr-2"></i> http://www.yuque.com/jtostring
                </a>
            </div>
        </div>
    </footer>
    
    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            },
            themeVariables: {
                primaryColor: '#E2E8F0',
                primaryBorderColor: '#64748B',
                primaryTextColor: '#1E293B',
                lineColor: '#94A3B8'
            }
        });
        
        // 平滑滚动
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
        
        // 滚动动画
        const observer = new IntersectionObserver((entries) => {
            entries.forEach(entry => {
                if (entry.isIntersecting) {
                    entry.target.classList.add('animate-fadeIn');
                }
            });
        }, { threshold: 0.1 });
        
        document.querySelectorAll('section').forEach(section => {
            observer.observe(section);
        });
    </script>
</body>
</html>